<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="../fragments/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="decorator" content="default"/>
</head>
<body>
<div title="应急机构管理" style="padding:10px">
    <table id="dg"  class="easyui-datagrid" style="height:400px"
           url="${ctx}/aid_org/dataGrid"
           toolbar="#toolbar" pagination="true"
           rownumbers="true" fitColumns="true" singleSelect="true" data-options="queryParams: {
                'pageSize' : function(){
                    return $('#dg').datagrid('getPager').pagination('options').pageSize;
                },
                'pageNumber' : function(){
                    return $('#dg').datagrid('getPager').pagination('options').pageNumber;
                }
            }">
        <thead>
        <tr>
            <th field="name" width="50">机构名称</th>
            <th field="contact" width="50">联系方式</th>
            <th field="pName" width="50">上级救援机构</th>
            <th data-options="field:'_operate',width:50,formatter:formatOper">操作</th>
        </tr>
        </thead>
    </table>
    <div id="toolbar">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newOrg()">新建</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editOrg()">编辑</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyOrg()">删除</a>
    </div>

    <div id="dlg" class="easyui-dialog" style="width:420px"
         closed="true" buttons="#dlg-buttons">
        <form id="fm" method="post" action="/aid_org/list" novalidate style="margin:0;padding:20px 50px">
            <div style="margin-bottom:20px;font-size:14px;border-bottom:1px solid #ccc">应急救援机构信息</div>
            <input type="hidden" name="id" id="id" value="0">
            <div style="margin-bottom:10px">
                <input name="name"  class="easyui-textbox" required="true" label="名称:" style="width:100%">
            </div>
            <div style="margin-bottom:10px">
                <input name="contact"  class="easyui-textbox" required="true" label="联系方式:" style="width:100%">
            </div>
            <div style="margin-bottom:10px">
                <span>类型:</span>&nbsp;&nbsp;&nbsp;
                <input name="type" type="radio" id="org_selected" class="easyui-validatebox" onclick="clickOrg();" value="0">救援机构
                <input name="type" type="radio" class="easyui-validatebox" onclick="clickGroup();"  value="1">前指
                <input name="type" type="radio" class="easyui-validatebox" onclick="clickGroup();"  value="1">后指
                <input name="type" type="radio" class="easyui-validatebox" onclick="clickGroup();"  value="1">总指
            </div>
            <div id="p_org" style="margin-bottom:10px">
                <select name="pid" id="" class="easyui-combobox" label="父级机构:" style="width:90%">
                    <c:forEach items="${orgList}" var="org">
                        <c:if test="${org.pid==0}">
                            <option value="${org.id}">${org.name}</option>
                        </c:if>
                    </c:forEach>
                </select>
            </div>
        </form>
    </div>

    <div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveOrg()" style="width:90px">保存</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">取消</a>
    </div>
    <script type="text/javascript">
        var url;
        function newOrg(){
            $('#dlg').dialog('open').dialog('center').dialog('setTitle','创建');
            $('#fm').form('clear');
            document.getElementById("org_selected").checked = true;//设置默认选中
            url = 'aid_org/edit';
        }
        function editOrg(){
            var row = $('#dg').datagrid('getSelected');
            if (row){
                $('#dlg').dialog('open').dialog('center').dialog('setTitle','编辑');
                $('#fm').form('load',row);
            }
        }
        function saveOrg(){
            $('#fm').form('submit',{
                url:"${pageContext.request.contextPath}/aid_org/edit",
                onSubmit: function(){
                    return $(this).form('validate');
                },
                success: function(result){
                    var result = eval('('+result+')');
                    if (result.status==1){
                        $.messager.show({
                            title: 'Error',
                            msg: result.msg
                        });
                    } else {
                        $('#dlg').dialog('close');        // close the dialog
                        $('#dg').datagrid('reload');    // reload the user data
                    }
                }
            });
        }
        function destroyOrg(){
            var row = $('#dg').datagrid('getSelected');
            if (row){
                $.messager.confirm('确认','确定删除吗？',function(r){
                    if (r){
                        $.post('${ctx}/aid_org/delete',{id:row.id},function(result){
                            if (result.status==0){
                                $('#dg').datagrid('reload');    // reload the user data
                            } else {
                                $.messager.show({    // show error message
                                    title: '错误',
                                    msg: result.msg
                                });
                            }
                        },'json');
                    }
                });
            }
        }
        $(function(){
            $("#p_org").hide();
        })
        function clickOrg(){
            $("#p_org").hide();
        }
        function clickGroup(){
            $("#p_org").show();
        }
        function formatOper(val,row,index){
            return '<a href="${ctx}/org_mem/viewOrgMem?id='+row.id+'">编辑机构成员</a>';
        }
    </script>
</div>
</body>
</html>
